package day07;

import java.io.RandomAccessFile;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Demo05 {

	public static void main(String[] args) throws Exception {
		String file="abc/emp.dat";
		RandomAccessFile raf=new RandomAccessFile(file,"r");
		Emp e1=read(raf,0);
		Emp e2=read(raf,1);
		System.out.println(e1);
		System.out.println(e2);
		
		raf.close();
		
	}
	
	public static Emp read(RandomAccessFile raf,int n) throws Exception{
		int start=n*80;
		raf.seek(start);
		byte[]bytes=new byte[32];
		raf.read(bytes);
		String name=new String(bytes,"UTF-8").trim();
		
		int age=raf.readInt();
		
		bytes=new byte[10];
		raf.read(bytes);
		String gender=new String(bytes,"UTF-8").trim();
		
		int salary=raf.readInt();
		
		bytes=new byte[12];
		raf.read(bytes);
		String date=new String(bytes,"UTF-8").trim();
		
		SimpleDateFormat fmt=new SimpleDateFormat("yyyy-MM-dd");
		Date hiredate=fmt.parse(date);
		
		return new Emp(name,age,gender,salary,hiredate);
		
		
	}
	

}
